<template>
    <Detail-dialog
    modal
    :closeOnClickModal="false"
    :width="40"
    :title="title"
    :show.sync="dialogShow" @close="close" @save="save('cdataForm')">
    <el-form :model="companyInfo" ref="cdataForm" label-width="150px" :rules="rules">
        <el-form-item  prop="realName">
                <template slot="label">
                <span>公司注册名称</span>
                <el-tooltip content="公司注册工商局的全名称" placement="top">
                  <i class="el-icon-question"></i>
                </el-tooltip>
              </template>
          <el-input class="wp-form-280" clearable v-model.trim="companyInfo.realName" placeholder="公司注册名称"></el-input>
      </el-form-item>
    </el-form>
    </Detail-dialog>
</template>

<script>
import DetailDialog from '@/components/DetailDialog'
import system from '@/api/system'
export default {
  props: {
    visible: Boolean,
    title: String,
    data: Object
  },
  watch: {
    visible: {
      handler (val) {
        this.dialogShow = val
      },
      immediate: true
    },
    data: {
      handler (val) {
        if (val) {
          this.companyInfo = {...val}
          this.companyInfo.realName = val.companyName
        }
      },
      deep: true,
      immediate: true
    },
    dialogShow (val) {
      this.$emit('update:visible', val)
    }
  },
  components: {DetailDialog},
  data () {
    return {
      dialogShow: false,
      companyInfo: {},
      rules: {
        realName: [{ required: true, message: '不能为空', trigger: 'blur' }]
      }
    }
  },
  methods: {
    close () {
      this.dialogShow = false
    },
    save (form) {
      this.$refs[form].validate(validte => {
        if (validte) {
          const parma = {}
          parma.realName = this.companyInfo.realName
          parma.companyCode = this.companyInfo.companyCode
          system.createAccountCompanyAPI(parma).then(res => {
            this.close()
            this.$emit('afterSave', res)
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
